home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * Catalog.js
- *
- * USAGE
- * Part of Netobjects JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2005 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
-
- if (!IS.isModuleInitialized("IS.NOF.Catalog"))
- {
- /****h* NOF_JavaScript_Library/NOF.Catalog
- *
- * NAME
- * NOF.Catalog
- *
- * DESCRIPTION
- *
- *
- ****/
-
- /**
- * Constructor
- * @param fsi_selection
- * @param profile
- * @param name
- */
- function NOF_Catalog(fsi_selection, profile, name){
- this.__proto__ = NOF_Catalog;
-
- //private variables
- this.app = NOF.App.getFSIApp();
- this.app2 = NOF.App.getFSIApp2();
-
- //public constants
- this.INDEX_IS_TABLE = 0x00000001;
- this.INDEX_INCLUDE_TITLE = 0x00000002;
- this.DISPLAY_LAYOUT_MASK = 0x0000000f;
- this.TABLE_GENERATED_MASK = 0x00000800;
-
- //public variables
- this.selection = fsi_selection;
- this.profile = profile;
- this.name = name;
- this.currentIndex = -1;
-
- this.list = new Array();
- this.indexInSelection = new Array();
-
- this.indexCatalog = null; //ThumbnailPage;
- this.displayCatalog = null; //PhotoPage;
-
- this.internalTableCreated =
- ( this.selection != null && this.selection.GetTable() != null);//this value should be verified in subclass !
-
- if ( this.internalTableCreated && this.selection.GetTable().Name!=null ) {
- this.name = this.selection.GetTable().Name; //read the real name of the catalog
- }
- }
-
- function NOF_Catalog_ProtoBuilder() {
-
- //interface
- var method = NOF_Catalog.prototype;
-
- method.getIndexCatalog = getIndexCatalog;
- method.getDisplayCatalog = getDisplayCatalog;
-
- method.setCurrentIndex = setCurrentIndex;
- method.getCurrentIndex = getCurrentIndex;
-
- method.get = get;
- method.add = add;
- method.removeAll = removeAll;
- method.remove = remove;
- method.size = size;
-
- method.swapItems = swapItems;
-
- method.alterTable = alterTable;
- method.createTable = createTable;
- method.setTable = setTable;
-
- method.isInternalTableCreated = isInternalTableCreated;
-
-
-
- //interface implementation
-
-
- /**
- * get a record from the list
- * @param i index of the the item
- * @return the i-th item in the list or currentIndex element, if i is null
- */
-
- function get (i){
- var index = this.currentIndex;
- if(i!=null){
- index = i;
- }
- return this.list[index];
- }
-
-
- function add(q, values, position) {
- var index = position != null ? position : this.list.length;
- this.list[index] = q; //add q element at the end of the list, modify here to insert it at a specified position
- this.indexInSelection[index] = index;
-
- // Update existing item
- if (position != null && position >= 0)
- this.selection.SetIndex(position);
- // Insert new Item
- else
- this.selection.NewRecord();
-
-
- for ( var i = 0; i < values.length; i++ ) {
- this.selection.SetField(values[i][0], values[i][1]);//write corresponding data into table fields
- }
- this.selection.Update();
- this.setCurrentIndex(index); //set current index the last element inserted
- }
-
-
- function getIndexCatalog(){
- return this.indexCatalog;
- }
-
- function getDisplayCatalog(){
- return this.displayCatalog;
- }
-
- function getCurrentIndex(){
- return this.currentIndex;
-
- }
-
- function removeAll() {
- for ( var i = this.size() - 1; i >= 0; i-- ) {
- if( this.remove( i ) == false ){
- //OO! ??
- }
- }
- this.list = new Array();
- this.indexInSelection = new Array();
-
- }
-
- function remove( index ){
-
- var i = (index != null ) ? index : this.currentIndex;
-
-
- var q = this.indexInSelection[i];
- //NOF.util_logging_ConsoleLogger_global.info( "Catalog.remove item "+i+" - in selection "+q);
-
- this.selection.SetIndex( q );
-
- var image = this.selection.GetField('Image');
- var displayflags = this.selection.GetField('ImageFlags') - 0;
- var displaywidth = this.selection.GetField('ImageWidth') - 0;
- var displayheight = this.selection.GetField('ImageHeight') - 0;
- var rotation = this.selection.GetField('ImageRotation') - 0;
- var displayquality = this.selection.GetField('ImageQuality') - 0;
- var displayformat = this.selection.GetField('ImageFormat');
- var indexflags = this.selection.GetField('ImageTnFlags') - 0;
- var indexwidth = this.selection.GetField('ImageTnWidth') - 0;
- var indexheight = this.selection.GetField('ImageTnHeight') - 0;
- var indexquality = this.selection.GetField('ImageTnQuality') - 0;
- var indexformat = this.selection.GetField('ImageTnFormat');
-
- //NOF.util_logging_ConsoleLogger_global.info( "Catalog.remove item from selection "+q+"\n imagePath="+image);
-
- if ((displayflags & this.TABLE_GENERATED_MASK) != 0)
- this.selection.FreeKey(image, displaywidth, displayheight, rotation, displayquality, displayformat);
-
- if ((indexflags & this.TABLE_GENERATED_MASK) != 0)
- this.selection.FreeKey(image, indexwidth, indexheight, rotation, indexquality, indexformat);
-
- this.selection.DeleteRecord();
- this.selection.Update();
-
- this.list.removeItem(i);
-
- this.indexInSelection.removeItem(i);
- // decrease all indexes in the selection greater than q
- for( var j = 0; j < this.indexInSelection.length; j++ ) {
- if( q <= this.indexInSelection[j] ) {
- this.indexInSelection[j] -= 1;
- }
- }
-
- if( i > 0 ) {
- this.setCurrentIndex( i-1 );
- } else {
- this.setCurrentIndex( 0 );
- }
-
- //NOF.util_logging_ConsoleLogger_global.info( "Catalog.remove "+ " this.indexInSelection = "+this.indexInSelection.join()+ "\n\n currentIndex=="+this.currentIndex);
-
- return true;
- }
-
- function swapItems(i1, i2){
-
- //NOF.util_logging_ConsoleLogger_global.info( "Catalog.swapItems "+i1+" - "+i2+", \n"+ this.list[i1].imagePath+"\n"+this.list[i2].imagePath+"\n"+ " indexInSelection = "+this.indexInSelection[i1]+" - "+this.indexInSelection[i2]);
-
- var tmp = this.list[i1];
- this.list[i1] = this.list[i2];
- this.list[i2] = tmp;
-
- var tmpI = this.indexInSelection[i1];
- this.indexInSelection[i1] = this.indexInSelection[i2];
- this.indexInSelection[i2] = tmpI;
-
- //NOF.util_logging_ConsoleLogger_global.info( "Catalog.swapItems "+i1+" - "+i2+", \n"+ this.list[i1].imagePath+"\n"+this.list[i2].imagePath+"\n"+ " indexInSelection = "+this.indexInSelection[i1]+" - "+this.indexInSelection[i2]+"\n\n"+ " this.indexInSelection = "+this.indexInSelection.join());
- }
-
- function size(){
- return this.selection.Count();
- //should be the same as this._list
- }
-
-
- function setCurrentIndex(index){
- //this.selection.SetIndex(index);
- this.currentIndex = index;
- }
-
- function setTable (table){
- return this.selection.SetTable(table);
- }
-
- function createTable (name,values){
- var theTable = this.app.NewTable(name);
- if (theTable){
- for(var i=0;i<values.length;i++)
- theTable.AddField(values[i][0],values[i][1]);
-
- this.internalTableCreated = this.selection.SetTable(theTable);
- }
- return this.internalTableCreated;
- }
-
- function alterTable(values){
- var theTable = this.selection.GetTable();
- if (theTable){
- for(var i=0;i<values.length;i++){
- if (! theTable.FieldExists(values[i][0])) {
- theTable.AddField(values[i][0],values[i][1]);
- }
- }
- }
- }
-
- function isInternalTableCreated() {
- return this.internalTableCreated;
- }
- }
-
- NOF_Catalog_ProtoBuilder();
- NOF.__proto__.Catalog = NOF_Catalog;
- }
-